package com.dinstar.linphone;

import android.content.Context;

import org.linphone.core.BuildConfig;
import org.linphone.core.Config;

public final class Preferences {
    private final static String TAG = Preferences.class.getSimpleName();
    private final static String CONFIG_FILE_NAME = ".linphonerc";
    private final static String ENCRYPTED_SHARED_PREFERENCES_FILE = "encrypted.pref";

    private final Context mContext;
    private final Config mConfig;

    public Preferences(Context mContext, Config config) {
        this.mContext = mContext;
        this.mConfig = config;
    }

    public Boolean getPrintLogsInLogcat() {
        return mConfig.getBool("app", "debug", BuildConfig.DEBUG);
    }

    public void setPrintLogsInLogcat(Boolean printLogsInLogcat) {
        mConfig.setBool("app", "debug", printLogsInLogcat);
    }

    public Boolean getKeepServiceAlive() {
        return mConfig.getBool("app", "keep_service_alive", false);
    }

    public void setKeepServiceAlive(Boolean keepServiceAlive) {
        mConfig.setBool("app", "keep_service_alive", keepServiceAlive);
    }

    public String getDeviceName() {
        return mConfig.getString("app", "device", "");
    }

    public void setDeviceName(String value) {
        mConfig.setString("app", "device", value.trim());
    }

    public Boolean getAutomaticallyStartCallRecording() {
        return mConfig.getBool("app", "auto_start_call_record", false);
    }

    public void setAutomaticallyStartCallRecording(Boolean value) {
        mConfig.setBool("app", "auto_start_call_record", value);
    }

    public int getVoiceRecordingMaxDuration() {
        return mConfig.getInt("app", "voice_recording_max_duration", 600000);
    }

    public void setVoiceRecordingMaxDuration(int value) {
        mConfig.setInt("app", "voice_recording_max_duration", value);
    }

    public Boolean getEnableSecureMode() {
        return mConfig.getBool("ui", "disable_call_recordings_feature", false);
    }

    public int getMaxAccountsCount() {
        return mConfig.getInt("ui", "max_account", 0);
    }

    public String getConfigPath() {
        return mContext.getFilesDir().getAbsolutePath() + "/" + CONFIG_FILE_NAME;
    }

    public String getFactoryConfigPath() {
        return mContext.getFilesDir().getAbsolutePath() + "/linphonerc";
    }

    public String getLinphoneDefaultValuesPath() {
        return mContext.getFilesDir().getAbsolutePath() + "/assistant_linphone_default_values";
    }

    public String getThirdPartyDefaultValuesPath() {
        return mContext.getFilesDir().getAbsolutePath() + "/assistant_third_party_default_values";
    }

    public String getVfsCachePath() {
        return mContext.getFilesDir().getAbsolutePath() + "/evfs/";
    }

    //    public void copyAssetsFromPackage() {
//        copy("linphonerc_default", configPath, false);
//        copy("linphonerc_factory", factoryConfigPath, true);
//        copy("assistant_linphone_default_values", linphoneDefaultValuesPath, true);
//        copy("assistant_third_party_default_values", thirdPartyDefaultValuesPath, true);
//    }
//
//    private void copy(String from, String to, boolean overwrite) {
//        File output = new File(to);
//        if (output.exists() && !overwrite) {
//            return;
//        }
//        FileOutputStream fos = new FileOutputStream(output);
//        File in = mContext.getAssets().open(from);
//
//    }
}
